/*
 * trans_s.h
 *
 * Created: 2012-07-13 11:23:53
 *  Author: Antrykot
 */ 



////////////////////// TRANS //////////////////////

void TS(u8 addr, u16 data, u8 repeat);

u8 trans_s();

void retrive_trans();

u8 crc();

#define FREQ_PLUS 190
#define FREQ_MINU 191

//#define TR_K_ENABLE EIMSK |= (1 << INT0)
//#define TR_K_DISABLE EIMSK &= ~(1 << INT0)

//#define TR_P_ENABLE EIMSK |= (1 << INT1)
//#define TR_P_DISABLE EIMSK &= ~(1 << INT1)

#define KTX_LOW	PORTD &= ~(1 << 5)		// pd1 tx - k
#define KTX_HIG	PORTD |= (1 << 5)		// pd1 tx - k
#define KRX ((PIND & (1 << 4)) >> 4)			// pd1 rx - k
#define KCLK_LOW PORTD &= ~(1 << 3)
#define KCLK_HIGH PORTD |= (1 << 3)



 
extern u8 rs_addr;
extern u16 rs_data;
extern u16 rs_pom;
extern u8 rs_crc;

extern u16 rs_pr;
extern u16 rs_tm;
extern u16 rs_rh;


extern u8 ts_addr;
extern u8 ts_crc;
extern u16 ts_data;

extern u8 crc_data[16];
extern u8 crc_data_len;

extern u8 trs_ok;

extern u8 ts_repeat;

void clk_s();
u8 crc();
u8 get_8b_s();
void set_8b_s(u8 data);
void add_crc8(u8 byte);
void add_crc16(u16 word);

void setup_int();

#define K_ADDR_VERSION					0x40

#define K_ADDR_SYNC						0x50

#define K_ADDR_CALFP					0x90
#define K_ADDR_CALFM					0x91

#define K_ADDR_HZ						0x61
#define K_ADDR_HS						0x62
#define K_ADDR_LZ						0x63
#define K_ADDR_LS						0x64

#define K_ADDR_ACCEPT					0x68
#define K_ADDR_DENY						0x69

#define K_ADDR_SERWIS					0x6E

#define K_ADDR_CAL_START				0x20
#define K_ADDR_CAL_FINISH				0x21
#define K_ADDR_CAL_STOP					0x22

#define K_ADDR_NR						0x30
#define K_ADDR_DATE						0x35

#define K_ADDR_DEBUG					0xA0
#define K_ADDR_DEBUG_AL					0xA1

#define K_ADDR_ALARMS					0xB0
#define K_ADDR_INPUT					0xB4

#define K_ADDR_KSP						0xC0

#define K_ADDR_RS_ASKNUM				0xD0

#define K_ADDR_LRANGE					0xC2
#define K_ADDR_HRANGE					0xC4
#define K_ADDR_PARAM					0xC6


#define K_ADDR_NO_COMM					0xBE

#define K_ADDR_BATT_VOLT				0xD8
#define K_ADDR_LINE_VOLT				0xD9
#define K_ADDR_LINE_LOAD				0xDA
#define K_ADDR_PELI_VOLT				0xDB

//#define EMPTY_BUFFER					0xFFFF